{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "d8471f33",
   "metadata": {},
   "source": [
    "## 1.了解数据"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8c6d3daa",
   "metadata": {},
   "source": [
    "### 1）加载必要的库"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "7cbef540",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import seaborn as sns\n",
    "import matplotlib.pyplot as plt\n",
    "import pyecharts"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "441d54d5",
   "metadata": {},
   "source": [
    "### 2)读取数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "9caa92e0",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>item_id</th>\n",
       "      <th>behavior_type</th>\n",
       "      <th>user_geohash</th>\n",
       "      <th>item_category</th>\n",
       "      <th>time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10001082</td>\n",
       "      <td>285259775</td>\n",
       "      <td>1</td>\n",
       "      <td>97lk14c</td>\n",
       "      <td>4076</td>\n",
       "      <td>2014-12-08 18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>10001082</td>\n",
       "      <td>4368907</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>5503</td>\n",
       "      <td>2014-12-12 12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>10001082</td>\n",
       "      <td>53616768</td>\n",
       "      <td>4</td>\n",
       "      <td>NaN</td>\n",
       "      <td>9762</td>\n",
       "      <td>2014-12-02 15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>10001082</td>\n",
       "      <td>9947871</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2825</td>\n",
       "      <td>2014-11-28 20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>10001082</td>\n",
       "      <td>150720867</td>\n",
       "      <td>1</td>\n",
       "      <td>95qoghe</td>\n",
       "      <td>3200</td>\n",
       "      <td>2014-12-15 08</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    user_id    item_id  behavior_type user_geohash  item_category  \\\n",
       "0  10001082  285259775              1      97lk14c           4076   \n",
       "1  10001082    4368907              1          NaN           5503   \n",
       "2  10001082   53616768              4          NaN           9762   \n",
       "3  10001082    9947871              1          NaN           2825   \n",
       "4  10001082  150720867              1      95qoghe           3200   \n",
       "\n",
       "            time  \n",
       "0  2014-12-08 18  \n",
       "1  2014-12-12 12  \n",
       "2  2014-12-02 15  \n",
       "3  2014-11-28 20  \n",
       "4  2014-12-15 08  "
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user=pd.read_csv('tianchi_fresh_comp_train_user.csv')\n",
    "user.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3f8f348c",
   "metadata": {},
   "source": [
    "### 3)快速查看数据类型和数据结构"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "532cb8c3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 15463110 entries, 0 to 15463109\n",
      "Data columns (total 6 columns):\n",
      " #   Column         Dtype \n",
      "---  ------         ----- \n",
      " 0   user_id        int64 \n",
      " 1   item_id        int64 \n",
      " 2   behavior_type  int64 \n",
      " 3   user_geohash   object\n",
      " 4   item_category  int64 \n",
      " 5   time           object\n",
      "dtypes: int64(4), object(2)\n",
      "memory usage: 707.8+ MB\n"
     ]
    }
   ],
   "source": [
    "user.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "01bf5052",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>item_id</th>\n",
       "      <th>behavior_type</th>\n",
       "      <th>item_category</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>1.546311e+07</td>\n",
       "      <td>1.546311e+07</td>\n",
       "      <td>1.546311e+07</td>\n",
       "      <td>1.546311e+07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>7.015207e+07</td>\n",
       "      <td>2.023169e+08</td>\n",
       "      <td>1.153780e+00</td>\n",
       "      <td>6.827181e+03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>4.572019e+07</td>\n",
       "      <td>1.167524e+08</td>\n",
       "      <td>5.440445e-01</td>\n",
       "      <td>3.810410e+03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>4.920000e+02</td>\n",
       "      <td>3.700000e+01</td>\n",
       "      <td>1.000000e+00</td>\n",
       "      <td>2.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>3.021406e+07</td>\n",
       "      <td>1.014015e+08</td>\n",
       "      <td>1.000000e+00</td>\n",
       "      <td>3.687000e+03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>5.638708e+07</td>\n",
       "      <td>2.022669e+08</td>\n",
       "      <td>1.000000e+00</td>\n",
       "      <td>6.054000e+03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>1.166482e+08</td>\n",
       "      <td>3.035247e+08</td>\n",
       "      <td>1.000000e+00</td>\n",
       "      <td>1.025800e+04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>1.424430e+08</td>\n",
       "      <td>4.045625e+08</td>\n",
       "      <td>4.000000e+00</td>\n",
       "      <td>1.408000e+04</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            user_id       item_id  behavior_type  item_category\n",
       "count  1.546311e+07  1.546311e+07   1.546311e+07   1.546311e+07\n",
       "mean   7.015207e+07  2.023169e+08   1.153780e+00   6.827181e+03\n",
       "std    4.572019e+07  1.167524e+08   5.440445e-01   3.810410e+03\n",
       "min    4.920000e+02  3.700000e+01   1.000000e+00   2.000000e+00\n",
       "25%    3.021406e+07  1.014015e+08   1.000000e+00   3.687000e+03\n",
       "50%    5.638708e+07  2.022669e+08   1.000000e+00   6.054000e+03\n",
       "75%    1.166482e+08  3.035247e+08   1.000000e+00   1.025800e+04\n",
       "max    1.424430e+08  4.045625e+08   4.000000e+00   1.408000e+04"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user.describe()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d1d2b6aa",
   "metadata": {},
   "source": [
    "### 4)统计缺失值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "8fc7a566",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "user_id                0\n",
       "item_id                0\n",
       "behavior_type          0\n",
       "user_geohash     8207386\n",
       "item_category          0\n",
       "time                   0\n",
       "dtype: int64"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user.isnull().sum()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "64868235",
   "metadata": {},
   "source": [
    "因为不做地理数据的分析user_geohash 这列的缺失值不做处理"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "94d9960b",
   "metadata": {},
   "source": [
    "## 2.处理数据"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "68a371c9",
   "metadata": {},
   "source": [
    "### 1）删除重复值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "ecfd59c3",
   "metadata": {},
   "outputs": [],
   "source": [
    "user.drop_duplicates(keep='last',inplace=True)\n",
    "#keep: {‘first’, ‘last’, False},默认为’first’\n",
    "# 保留项。保留第一个（first）/最后一个（last）/不保留（False）重复的项"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ec89fea4",
   "metadata": {},
   "source": [
    "### 2)将time转换为datetime格式"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "d4a642e8",
   "metadata": {},
   "outputs": [],
   "source": [
    "user['time']=pd.to_datetime(user['time'])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cac4ff4a",
   "metadata": {},
   "source": [
    "### 3) 提取出日期和时间"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "66eaa443",
   "metadata": {},
   "outputs": [],
   "source": [
    "user['dates']=user.time.dt.date\n",
    "user['month']=user.dates.values.astype('datetime64[M]')\n",
    "user['hour']=user.time.dt.hour"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "450a7910",
   "metadata": {},
   "source": [
    "### 4)转换数据类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "1568021b",
   "metadata": {},
   "outputs": [],
   "source": [
    "user['behavior_type']=user['behavior_type'].apply(str)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "e8c4c0c6",
   "metadata": {},
   "outputs": [],
   "source": [
    "user['user_id']=user['user_id'].apply(str)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "122bbe8e",
   "metadata": {},
   "outputs": [],
   "source": [
    "user['item_id']=user['item_id'].apply(str)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "11c719fe",
   "metadata": {},
   "source": [
    "## 3.数据分析——可视化"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7a549e06",
   "metadata": {},
   "source": [
    "### 1）统计每日PV和UV数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "93dd36d1",
   "metadata": {},
   "outputs": [],
   "source": [
    "pv_day=user[user.behavior_type=='1'].groupby('dates')['behavior_type'].count()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "b68ecc80",
   "metadata": {},
   "outputs": [],
   "source": [
    "uv_day=user[user.behavior_type=='1'].drop_duplicates(['user_id','dates']).groupby('dates')['behavior_type'].count()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e33a1dc6",
   "metadata": {},
   "source": [
    "### 2)分析每天的pv和uv的趋势"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "1d10d165",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pyecharts.options as opts\n",
    "from pyecharts.charts import Line\n",
    "from pyecharts.charts import Grid\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "879b4bcc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"bd7728b5127c49049005d9b11ab83776\" style=\"width:1000px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_bd7728b5127c49049005d9b11ab83776 = echarts.init(\n",
       "                    document.getElementById('bd7728b5127c49049005d9b11ab83776'), 'white', {renderer: 'canvas'});\n",
       "                var option_bd7728b5127c49049005d9b11ab83776 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"line\",\n",
       "            \"name\": \"pv\",\n",
       "            \"connectNulls\": false,\n",
       "            \"symbolSize\": 4,\n",
       "            \"showSymbol\": true,\n",
       "            \"smooth\": false,\n",
       "            \"clip\": true,\n",
       "            \"step\": false,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    \"2014-11-18\",\n",
       "                    39.6\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-19\",\n",
       "                    40.51\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-20\",\n",
       "                    39.26\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-21\",\n",
       "                    37.26\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-22\",\n",
       "                    39.06\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-23\",\n",
       "                    42.82\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-24\",\n",
       "                    42.07\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-25\",\n",
       "                    40.36\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-26\",\n",
       "                    39.7\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-27\",\n",
       "                    40.48\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-28\",\n",
       "                    38.38\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-29\",\n",
       "                    39.83\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-30\",\n",
       "                    43.89\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-01\",\n",
       "                    43.54\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-02\",\n",
       "                    44.07\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-03\",\n",
       "                    45.78\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-04\",\n",
       "                    43.18\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-05\",\n",
       "                    40.09\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-06\",\n",
       "                    45.56\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-07\",\n",
       "                    47.82\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-08\",\n",
       "                    48.12\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-09\",\n",
       "                    49.49\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-10\",\n",
       "                    51.04\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-11\",\n",
       "                    61.22\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-12\",\n",
       "                    83.3\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-13\",\n",
       "                    49.44\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-14\",\n",
       "                    50.04\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-15\",\n",
       "                    48.91\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-16\",\n",
       "                    47.69\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-17\",\n",
       "                    46.87\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-18\",\n",
       "                    45.94\n",
       "                ]\n",
       "            ],\n",
       "            \"hoverAnimation\": true,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"lineStyle\": {\n",
       "                \"show\": true,\n",
       "                \"width\": 1,\n",
       "                \"opacity\": 1,\n",
       "                \"curveness\": 0,\n",
       "                \"type\": \"solid\"\n",
       "            },\n",
       "            \"areaStyle\": {\n",
       "                \"opacity\": 0\n",
       "            },\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 0\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"line\",\n",
       "            \"name\": \"uv\",\n",
       "            \"connectNulls\": false,\n",
       "            \"yAxisIndex\": 1,\n",
       "            \"symbolSize\": 4,\n",
       "            \"showSymbol\": true,\n",
       "            \"smooth\": false,\n",
       "            \"clip\": true,\n",
       "            \"step\": false,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    \"2014-11-18\",\n",
       "                    1.25\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-19\",\n",
       "                    1.26\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-20\",\n",
       "                    1.25\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-21\",\n",
       "                    1.23\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-22\",\n",
       "                    1.22\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-23\",\n",
       "                    1.26\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-24\",\n",
       "                    1.27\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-25\",\n",
       "                    1.26\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-26\",\n",
       "                    1.24\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-27\",\n",
       "                    1.24\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-28\",\n",
       "                    1.22\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-29\",\n",
       "                    1.22\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-30\",\n",
       "                    1.25\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-01\",\n",
       "                    1.28\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-02\",\n",
       "                    1.28\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-03\",\n",
       "                    1.3\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-04\",\n",
       "                    1.28\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-05\",\n",
       "                    1.26\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-06\",\n",
       "                    1.26\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-07\",\n",
       "                    1.29\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-08\",\n",
       "                    1.3\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-09\",\n",
       "                    1.3\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-10\",\n",
       "                    1.31\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-11\",\n",
       "                    1.38\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-12\",\n",
       "                    1.53\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-13\",\n",
       "                    1.33\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-14\",\n",
       "                    1.32\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-15\",\n",
       "                    1.34\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-16\",\n",
       "                    1.33\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-17\",\n",
       "                    1.3\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-18\",\n",
       "                    1.3\n",
       "                ]\n",
       "            ],\n",
       "            \"hoverAnimation\": true,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"lineStyle\": {\n",
       "                \"show\": true,\n",
       "                \"width\": 1,\n",
       "                \"opacity\": 1,\n",
       "                \"curveness\": 0,\n",
       "                \"type\": \"solid\"\n",
       "            },\n",
       "            \"areaStyle\": {\n",
       "                \"opacity\": 0\n",
       "            },\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 0\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"pv\",\n",
       "                \"uv\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"pv\": true,\n",
       "                \"uv\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"axis\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"cross\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"xAxis\": [\n",
       "        {\n",
       "            \"type\": \"category\",\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"axisPointer\": {\n",
       "                \"show\": true,\n",
       "                \"type\": \"shadow\"\n",
       "            },\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            },\n",
       "            \"data\": [\n",
       "                \"2014-11-18\",\n",
       "                \"2014-11-19\",\n",
       "                \"2014-11-20\",\n",
       "                \"2014-11-21\",\n",
       "                \"2014-11-22\",\n",
       "                \"2014-11-23\",\n",
       "                \"2014-11-24\",\n",
       "                \"2014-11-25\",\n",
       "                \"2014-11-26\",\n",
       "                \"2014-11-27\",\n",
       "                \"2014-11-28\",\n",
       "                \"2014-11-29\",\n",
       "                \"2014-11-30\",\n",
       "                \"2014-12-01\",\n",
       "                \"2014-12-02\",\n",
       "                \"2014-12-03\",\n",
       "                \"2014-12-04\",\n",
       "                \"2014-12-05\",\n",
       "                \"2014-12-06\",\n",
       "                \"2014-12-07\",\n",
       "                \"2014-12-08\",\n",
       "                \"2014-12-09\",\n",
       "                \"2014-12-10\",\n",
       "                \"2014-12-11\",\n",
       "                \"2014-12-12\",\n",
       "                \"2014-12-13\",\n",
       "                \"2014-12-14\",\n",
       "                \"2014-12-15\",\n",
       "                \"2014-12-16\",\n",
       "                \"2014-12-17\",\n",
       "                \"2014-12-18\"\n",
       "            ]\n",
       "        }\n",
       "    ],\n",
       "    \"yAxis\": [\n",
       "        {\n",
       "            \"type\": \"value\",\n",
       "            \"name\": \"pv\",\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"interval\": 20,\n",
       "            \"gridIndex\": 0,\n",
       "            \"axisTick\": {\n",
       "                \"show\": true,\n",
       "                \"alignWithLabel\": false,\n",
       "                \"inside\": false\n",
       "            },\n",
       "            \"axisLabel\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8,\n",
       "                \"formatter\": \"{value} \\u4e07\\u6b21\"\n",
       "            },\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"min\": 0,\n",
       "            \"max\": 100,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": true,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"value\",\n",
       "            \"name\": \"uv\",\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"interval\": 0.4,\n",
       "            \"gridIndex\": 0,\n",
       "            \"axisLabel\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8,\n",
       "                \"formatter\": \"{value} \\u4e07\\u4eba\"\n",
       "            },\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"min\": 0,\n",
       "            \"max\": 1.6,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"pv\\u4e0euv\\u8d8b\\u52bf\\u56fe\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_bd7728b5127c49049005d9b11ab83776.setOption(option_bd7728b5127c49049005d9b11ab83776);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x210c5121a30>"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "\n",
    "# 做出每天的pv与uv趋势图\n",
    "attr=list(pv_day.index)\n",
    "pv=(\n",
    "    Line(init_opts=opts.InitOpts(width=\"1000px\",height=\"500px\"))\n",
    "    .add_xaxis(xaxis_data=attr)\n",
    "    .add_yaxis(\n",
    "        \"pv\",\n",
    "        np.around(pv_day.values/10000,decimals=2),\n",
    "        label_opts=opts.LabelOpts(is_show=False)\n",
    "    )\n",
    "    .add_yaxis(\n",
    "        series_name=\"uv\",\n",
    "        yaxis_index=1,\n",
    "        y_axis=np.around(uv_day.values/10000,decimals=2),\n",
    "        label_opts=opts.LabelOpts(is_show=False),\n",
    "    )\n",
    "    .extend_axis(\n",
    "        yaxis=opts.AxisOpts(\n",
    "            name=\"uv\",\n",
    "            type_=\"value\",\n",
    "            min_=0,\n",
    "            max_=1.6,\n",
    "            interval=0.4,\n",
    "            axislabel_opts=opts.LabelOpts(formatter=\"{value} 万人\"),\n",
    "        )\n",
    "    )\n",
    "    .set_global_opts(\n",
    "        tooltip_opts=opts.TooltipOpts(\n",
    "            is_show=True,trigger=\"axis\",axis_pointer_type=\"cross\"\n",
    "        ),\n",
    "        xaxis_opts=opts.AxisOpts(\n",
    "            type_=\"category\",\n",
    "            axispointer_opts=opts.AxisPointerOpts(is_show=True,type_=\"shadow\"),\n",
    "        ),\n",
    "        yaxis_opts=opts.AxisOpts(\n",
    "            name=\"pv\",\n",
    "            type_=\"value\",\n",
    "            min_=0,\n",
    "            max_=100,\n",
    "            interval=20,\n",
    "            axislabel_opts=opts.LabelOpts(formatter=\"{value} 万次\"),\n",
    "            axistick_opts=opts.AxisTickOpts(is_show=True),\n",
    "            splitline_opts=opts.SplitLineOpts(is_show=True),\n",
    "        ),\n",
    "        title_opts=opts.TitleOpts(title=\"pv与uv趋势图\"),\n",
    "    )\n",
    ")\n",
    "\n",
    "pv.render_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8df0b097",
   "metadata": {},
   "source": [
    "### 3) pv,uv差异分析（by day）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "2924cd1c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>pv_day</th>\n",
       "      <th>uv_day</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>dates</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2014-11-18</th>\n",
       "      <td>395982</td>\n",
       "      <td>12530</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2014-11-19</th>\n",
       "      <td>405103</td>\n",
       "      <td>12591</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2014-11-20</th>\n",
       "      <td>392599</td>\n",
       "      <td>12520</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2014-11-21</th>\n",
       "      <td>372570</td>\n",
       "      <td>12292</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2014-11-22</th>\n",
       "      <td>390638</td>\n",
       "      <td>12170</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            pv_day  uv_day\n",
       "dates                     \n",
       "2014-11-18  395982   12530\n",
       "2014-11-19  405103   12591\n",
       "2014-11-20  392599   12520\n",
       "2014-11-21  372570   12292\n",
       "2014-11-22  390638   12170"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pv_uv=pd.concat([pv_day,uv_day],join='outer',axis=1)\n",
    "pv_uv.columns=['pv_day','uv_day']\n",
    "\n",
    "pv_uv.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "1ca69ffa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>new_pv</th>\n",
       "      <th>new_uv</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>dates</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2014-11-18</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2014-11-19</th>\n",
       "      <td>9121.0</td>\n",
       "      <td>61.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2014-11-20</th>\n",
       "      <td>-12504.0</td>\n",
       "      <td>-71.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2014-11-21</th>\n",
       "      <td>-20029.0</td>\n",
       "      <td>-228.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2014-11-22</th>\n",
       "      <td>18068.0</td>\n",
       "      <td>-122.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             new_pv  new_uv\n",
       "dates                      \n",
       "2014-11-18      NaN     NaN\n",
       "2014-11-19   9121.0    61.0\n",
       "2014-11-20 -12504.0   -71.0\n",
       "2014-11-21 -20029.0  -228.0\n",
       "2014-11-22  18068.0  -122.0"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_day=pv_uv.diff()\n",
    "new_day.columns=['new_pv','new_uv']\n",
    "new_day.head()#后一天减前一天"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "89b87a03",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"8354d7607b2746b1b43f43ed7d1c7143\" style=\"width:1000px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_8354d7607b2746b1b43f43ed7d1c7143 = echarts.init(\n",
       "                    document.getElementById('8354d7607b2746b1b43f43ed7d1c7143'), 'white', {renderer: 'canvas'});\n",
       "                var option_8354d7607b2746b1b43f43ed7d1c7143 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"line\",\n",
       "            \"name\": \"\\u65b0\\u589epv\",\n",
       "            \"connectNulls\": false,\n",
       "            \"symbolSize\": 4,\n",
       "            \"showSymbol\": true,\n",
       "            \"smooth\": false,\n",
       "            \"clip\": true,\n",
       "            \"step\": false,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    \"2014-11-18\",\n",
       "                    null\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-19\",\n",
       "                    9121.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-20\",\n",
       "                    -12504.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-21\",\n",
       "                    -20029.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-22\",\n",
       "                    18068.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-23\",\n",
       "                    37567.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-24\",\n",
       "                    -7484.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-25\",\n",
       "                    -17090.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-26\",\n",
       "                    -6583.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-27\",\n",
       "                    7738.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-28\",\n",
       "                    -21030.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-29\",\n",
       "                    14585.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-30\",\n",
       "                    40563.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-01\",\n",
       "                    -3456.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-02\",\n",
       "                    5281.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-03\",\n",
       "                    17074.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-04\",\n",
       "                    -25985.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-05\",\n",
       "                    -30945.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-06\",\n",
       "                    54759.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-07\",\n",
       "                    22581.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-08\",\n",
       "                    3030.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-09\",\n",
       "                    13630.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-10\",\n",
       "                    15549.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-11\",\n",
       "                    101816.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-12\",\n",
       "                    220781.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-13\",\n",
       "                    -338647.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-14\",\n",
       "                    6078.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-15\",\n",
       "                    -11345.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-16\",\n",
       "                    -12248.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-17\",\n",
       "                    -8157.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-18\",\n",
       "                    -9338.0\n",
       "                ]\n",
       "            ],\n",
       "            \"hoverAnimation\": true,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"lineStyle\": {\n",
       "                \"show\": true,\n",
       "                \"width\": 1,\n",
       "                \"opacity\": 1,\n",
       "                \"curveness\": 0,\n",
       "                \"type\": \"solid\"\n",
       "            },\n",
       "            \"areaStyle\": {\n",
       "                \"opacity\": 0\n",
       "            },\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 0\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"line\",\n",
       "            \"name\": \"\\u65b0\\u589euv\",\n",
       "            \"connectNulls\": false,\n",
       "            \"yAxisIndex\": \"1\",\n",
       "            \"symbolSize\": 4,\n",
       "            \"showSymbol\": true,\n",
       "            \"smooth\": false,\n",
       "            \"clip\": true,\n",
       "            \"step\": false,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    \"2014-11-18\",\n",
       "                    null\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-19\",\n",
       "                    61.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-20\",\n",
       "                    -71.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-21\",\n",
       "                    -228.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-22\",\n",
       "                    -122.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-23\",\n",
       "                    432.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-24\",\n",
       "                    140.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-25\",\n",
       "                    -178.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-26\",\n",
       "                    -138.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-27\",\n",
       "                    -61.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-28\",\n",
       "                    -208.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-29\",\n",
       "                    4.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-30\",\n",
       "                    342.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-01\",\n",
       "                    300.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-02\",\n",
       "                    -7.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-03\",\n",
       "                    157.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-04\",\n",
       "                    -111.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-05\",\n",
       "                    -237.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-06\",\n",
       "                    37.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-07\",\n",
       "                    291.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-08\",\n",
       "                    30.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-09\",\n",
       "                    -10.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-10\",\n",
       "                    117.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-11\",\n",
       "                    694.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-12\",\n",
       "                    1542.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-13\",\n",
       "                    -1988.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-14\",\n",
       "                    -130.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-15\",\n",
       "                    238.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-16\",\n",
       "                    -166.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-17\",\n",
       "                    -218.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-18\",\n",
       "                    -77.0\n",
       "                ]\n",
       "            ],\n",
       "            \"hoverAnimation\": true,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"lineStyle\": {\n",
       "                \"show\": true,\n",
       "                \"width\": 1,\n",
       "                \"opacity\": 1,\n",
       "                \"curveness\": 0,\n",
       "                \"type\": \"solid\"\n",
       "            },\n",
       "            \"areaStyle\": {\n",
       "                \"opacity\": 0\n",
       "            },\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 0\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u65b0\\u589epv\",\n",
       "                \"\\u65b0\\u589euv\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\\u65b0\\u589epv\": true,\n",
       "                \"\\u65b0\\u589euv\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"axis\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"cross\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"xAxis\": [\n",
       "        {\n",
       "            \"type\": \"category\",\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"axisPointer\": {\n",
       "                \"show\": true,\n",
       "                \"type\": \"shadow\"\n",
       "            },\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            },\n",
       "            \"data\": null\n",
       "        }\n",
       "    ],\n",
       "    \"yAxis\": [\n",
       "        {\n",
       "            \"type\": \"value\",\n",
       "            \"name\": \"\\u65b0\\u589epv\",\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"interval\": 100000,\n",
       "            \"gridIndex\": 0,\n",
       "            \"axisTick\": {\n",
       "                \"show\": true,\n",
       "                \"alignWithLabel\": false,\n",
       "                \"inside\": false\n",
       "            },\n",
       "            \"axisLabel\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8,\n",
       "                \"formatter\": \"{value}\"\n",
       "            },\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"min\": -350000,\n",
       "            \"max\": 250000,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": true,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"value\",\n",
       "            \"name\": \"\\u65b0\\u589euv\",\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"interval\": 400,\n",
       "            \"gridIndex\": 0,\n",
       "            \"axisLabel\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8,\n",
       "                \"formatter\": \"{value}\"\n",
       "            },\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"min\": -2000,\n",
       "            \"max\": 1600,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"pv,uv\\u5dee\\u5f02\\u5206\\u6790\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_8354d7607b2746b1b43f43ed7d1c7143.setOption(option_8354d7607b2746b1b43f43ed7d1c7143);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x212047cce20>"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "attr=new_day.index\n",
    "v=new_day.new_uv\n",
    "w=new_day.new_pv\n",
    "\n",
    "li=(\n",
    "    Line(init_opts=opts.InitOpts(width='1000px',height='500px'))\n",
    "    .add_xaxis(xaxis_data=attr)\n",
    "    .add_yaxis(\n",
    "        '新增pv',\n",
    "        w,\n",
    "        label_opts=opts.LabelOpts(is_show=False)\n",
    "    )\n",
    "    .extend_axis(\n",
    "        yaxis=opts.AxisOpts(\n",
    "            name='新增uv',\n",
    "            type_='value',\n",
    "            min_=-2000,\n",
    "            max_=1600,\n",
    "            interval=400,\n",
    "            axislabel_opts=opts.LabelOpts(formatter=\"{value}\")\n",
    "        )\n",
    "    )\n",
    "    .set_global_opts(\n",
    "        tooltip_opts=opts.TooltipOpts(\n",
    "            is_show=True,trigger='axis',axis_pointer_type='cross'\n",
    "        ),\n",
    "        xaxis_opts=opts.AxisOpts(\n",
    "            type_='category',\n",
    "            axispointer_opts=opts.AxisPointerOpts(is_show=True,type_='shadow')\n",
    "        ),\n",
    "        yaxis_opts=opts.AxisOpts(\n",
    "            name='新增pv',\n",
    "            type_='value',\n",
    "            min_=-350000,\n",
    "            max_=250000,\n",
    "            interval=100000,\n",
    "            axislabel_opts=opts.LabelOpts(formatter='{value}'),\n",
    "            axistick_opts=opts.AxisTickOpts(is_show=True),\n",
    "            splitline_opts=opts.SplitLineOpts(is_show=True)\n",
    "        ),\n",
    "        title_opts=opts.TitleOpts(title='pv,uv差异分析')\n",
    "    )\n",
    "    \n",
    "    )\n",
    "il=(Line()\n",
    "    .add_xaxis(xaxis_data=attr)\n",
    "    .add_yaxis(\"新增uv\",v,yaxis_index='1',label_opts=opts.LabelOpts(is_show=False),)\n",
    ")\n",
    "c=li.overlap(il)\n",
    "c.render_notebook()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d302c97e",
   "metadata": {},
   "source": [
    "### 4） 不同时期用户行为分析"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "d957046c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"aba6d5637f8a4ccda06500e823b353d2\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_aba6d5637f8a4ccda06500e823b353d2 = echarts.init(\n",
       "                    document.getElementById('aba6d5637f8a4ccda06500e823b353d2'), 'white', {renderer: 'canvas'});\n",
       "                var option_aba6d5637f8a4ccda06500e823b353d2 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"line\",\n",
       "            \"name\": \"\\u52a0\\u8d2d\\u4eba\\u6570\",\n",
       "            \"connectNulls\": false,\n",
       "            \"symbolSize\": 4,\n",
       "            \"showSymbol\": true,\n",
       "            \"smooth\": false,\n",
       "            \"clip\": true,\n",
       "            \"step\": false,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    \"2014-11-18\",\n",
       "                    18703\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-19\",\n",
       "                    18137\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-20\",\n",
       "                    17883\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-21\",\n",
       "                    17310\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-22\",\n",
       "                    17323\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-23\",\n",
       "                    18842\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-24\",\n",
       "                    18676\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-25\",\n",
       "                    19162\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-26\",\n",
       "                    17282\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-27\",\n",
       "                    17311\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-28\",\n",
       "                    16471\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-29\",\n",
       "                    17494\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-30\",\n",
       "                    20126\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-01\",\n",
       "                    20584\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-02\",\n",
       "                    21770\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-03\",\n",
       "                    22197\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-04\",\n",
       "                    20298\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-05\",\n",
       "                    19931\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-06\",\n",
       "                    20193\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-07\",\n",
       "                    20885\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-08\",\n",
       "                    21459\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-09\",\n",
       "                    22083\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-10\",\n",
       "                    23254\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-11\",\n",
       "                    30137\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-12\",\n",
       "                    46593\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-13\",\n",
       "                    19724\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-14\",\n",
       "                    20131\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-15\",\n",
       "                    19315\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-16\",\n",
       "                    19684\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-17\",\n",
       "                    19082\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-18\",\n",
       "                    18095\n",
       "                ]\n",
       "            ],\n",
       "            \"hoverAnimation\": true,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"lineStyle\": {\n",
       "                \"show\": true,\n",
       "                \"width\": 1,\n",
       "                \"opacity\": 1,\n",
       "                \"curveness\": 0,\n",
       "                \"type\": \"solid\"\n",
       "            },\n",
       "            \"areaStyle\": {\n",
       "                \"opacity\": 0\n",
       "            },\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 0\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"line\",\n",
       "            \"name\": \"\\u6536\\u85cf\\u4eba\\u6570\",\n",
       "            \"connectNulls\": false,\n",
       "            \"symbolSize\": 4,\n",
       "            \"showSymbol\": true,\n",
       "            \"smooth\": false,\n",
       "            \"clip\": true,\n",
       "            \"step\": false,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    \"2014-11-18\",\n",
       "                    13205\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-19\",\n",
       "                    13432\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-20\",\n",
       "                    13111\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-21\",\n",
       "                    12606\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-22\",\n",
       "                    12975\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-23\",\n",
       "                    14529\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-24\",\n",
       "                    13874\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-25\",\n",
       "                    13275\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-26\",\n",
       "                    13530\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-27\",\n",
       "                    13850\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-28\",\n",
       "                    13328\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-29\",\n",
       "                    13545\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-30\",\n",
       "                    14715\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-01\",\n",
       "                    14335\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-02\",\n",
       "                    15312\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-03\",\n",
       "                    16378\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-04\",\n",
       "                    15586\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-05\",\n",
       "                    14517\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-06\",\n",
       "                    15148\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-07\",\n",
       "                    16247\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-08\",\n",
       "                    15771\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-09\",\n",
       "                    15773\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-10\",\n",
       "                    15185\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-11\",\n",
       "                    16817\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-12\",\n",
       "                    19811\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-13\",\n",
       "                    14585\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-14\",\n",
       "                    15782\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-15\",\n",
       "                    15171\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-16\",\n",
       "                    14498\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-17\",\n",
       "                    14783\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-18\",\n",
       "                    13805\n",
       "                ]\n",
       "            ],\n",
       "            \"hoverAnimation\": true,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"lineStyle\": {\n",
       "                \"show\": true,\n",
       "                \"width\": 1,\n",
       "                \"opacity\": 1,\n",
       "                \"curveness\": 0,\n",
       "                \"type\": \"solid\"\n",
       "            },\n",
       "            \"areaStyle\": {\n",
       "                \"opacity\": 0\n",
       "            },\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 0\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"line\",\n",
       "            \"name\": \"\\u8d2d\\u4e70\\u4eba\\u6570\",\n",
       "            \"connectNulls\": false,\n",
       "            \"symbolSize\": 4,\n",
       "            \"showSymbol\": true,\n",
       "            \"smooth\": false,\n",
       "            \"clip\": true,\n",
       "            \"step\": false,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    \"2014-11-18\",\n",
       "                    6115\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-19\",\n",
       "                    5859\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-20\",\n",
       "                    5787\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-21\",\n",
       "                    5701\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-22\",\n",
       "                    5762\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-23\",\n",
       "                    6011\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-24\",\n",
       "                    6337\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-25\",\n",
       "                    6304\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-26\",\n",
       "                    5968\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-27\",\n",
       "                    6234\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-28\",\n",
       "                    5563\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-29\",\n",
       "                    5764\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-30\",\n",
       "                    6382\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-01\",\n",
       "                    6500\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-02\",\n",
       "                    6642\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-03\",\n",
       "                    6919\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-04\",\n",
       "                    6531\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-05\",\n",
       "                    5587\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-06\",\n",
       "                    6034\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-07\",\n",
       "                    6049\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-08\",\n",
       "                    6172\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-09\",\n",
       "                    5927\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-10\",\n",
       "                    6166\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-11\",\n",
       "                    6273\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-12\",\n",
       "                    28234\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-13\",\n",
       "                    6428\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-14\",\n",
       "                    6306\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-15\",\n",
       "                    6786\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-16\",\n",
       "                    6800\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-17\",\n",
       "                    6530\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-18\",\n",
       "                    6384\n",
       "                ]\n",
       "            ],\n",
       "            \"hoverAnimation\": true,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"lineStyle\": {\n",
       "                \"show\": true,\n",
       "                \"width\": 1,\n",
       "                \"opacity\": 1,\n",
       "                \"curveness\": 0,\n",
       "                \"type\": \"solid\"\n",
       "            },\n",
       "            \"areaStyle\": {\n",
       "                \"opacity\": 0\n",
       "            },\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 0\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u52a0\\u8d2d\\u4eba\\u6570\",\n",
       "                \"\\u6536\\u85cf\\u4eba\\u6570\",\n",
       "                \"\\u8d2d\\u4e70\\u4eba\\u6570\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\\u52a0\\u8d2d\\u4eba\\u6570\": true,\n",
       "                \"\\u6536\\u85cf\\u4eba\\u6570\": true,\n",
       "                \"\\u8d2d\\u4e70\\u4eba\\u6570\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"xAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            },\n",
       "            \"data\": [\n",
       "                \"2014-11-18\",\n",
       "                \"2014-11-19\",\n",
       "                \"2014-11-20\",\n",
       "                \"2014-11-21\",\n",
       "                \"2014-11-22\",\n",
       "                \"2014-11-23\",\n",
       "                \"2014-11-24\",\n",
       "                \"2014-11-25\",\n",
       "                \"2014-11-26\",\n",
       "                \"2014-11-27\",\n",
       "                \"2014-11-28\",\n",
       "                \"2014-11-29\",\n",
       "                \"2014-11-30\",\n",
       "                \"2014-12-01\",\n",
       "                \"2014-12-02\",\n",
       "                \"2014-12-03\",\n",
       "                \"2014-12-04\",\n",
       "                \"2014-12-05\",\n",
       "                \"2014-12-06\",\n",
       "                \"2014-12-07\",\n",
       "                \"2014-12-08\",\n",
       "                \"2014-12-09\",\n",
       "                \"2014-12-10\",\n",
       "                \"2014-12-11\",\n",
       "                \"2014-12-12\",\n",
       "                \"2014-12-13\",\n",
       "                \"2014-12-14\",\n",
       "                \"2014-12-15\",\n",
       "                \"2014-12-16\",\n",
       "                \"2014-12-17\",\n",
       "                \"2014-12-18\"\n",
       "            ]\n",
       "        }\n",
       "    ],\n",
       "    \"yAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u4e0d\\u540c\\u65f6\\u671f\\u7528\\u6237\\u884c\\u4e3a\\u6570\\u636e\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_aba6d5637f8a4ccda06500e823b353d2.setOption(option_aba6d5637f8a4ccda06500e823b353d2);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x211767a0040>"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "shopping_cart=user[user.behavior_type=='3'].groupby('dates')['behavior_type'].count()\n",
    "collect=user[user.behavior_type=='2'].groupby('dates')['behavior_type'].count()\n",
    "buy=user[user.behavior_type=='4'].groupby('dates')['behavior_type'].count()\n",
    "\n",
    "attr_a=list(shopping_cart.index)\n",
    "v_1=shopping_cart.values.tolist()\n",
    "v_2=collect.values.tolist()\n",
    "v_3=buy.values.tolist()\n",
    "\n",
    "b=(\n",
    "    Line()\n",
    "    .add_xaxis(xaxis_data=attr_a)\n",
    "    .add_yaxis(\n",
    "        '加购人数',\n",
    "        v_1,\n",
    "        label_opts=opts.LabelOpts(is_show=False)\n",
    "    )\n",
    "    .add_yaxis(\n",
    "         '收藏人数',\n",
    "        v_2,\n",
    "        label_opts=opts.LabelOpts(is_show=False)\n",
    "    )\n",
    "    .add_yaxis(\n",
    "         '购买人数',\n",
    "        v_3,\n",
    "        label_opts=opts.LabelOpts(is_show=False)\n",
    "    )\n",
    "    .set_global_opts(title_opts=opts.TitleOpts(title='不同时期用户行为数据'))\n",
    ")\n",
    "b.render_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cf9f1c25",
   "metadata": {},
   "source": [
    "## 4、把数据拆分为活动数据和日常数据做不同时段的分析\n",
    "——由于数据里面包含双十二大促的数据，因此整理分析用户的不同时段行为可能会导致分析结果与实际差异较大，因此拆分开来做不同的对比分析\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9b3c541d",
   "metadata": {},
   "source": [
    "### 1）把dates列转换为datetime类型\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "573219c8",
   "metadata": {},
   "outputs": [],
   "source": [
    "user['dates']=pd.to_datetime(user['dates'])\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "43d05bd5",
   "metadata": {},
   "source": [
    "### 2）选取活动数据子集和日常数据子集"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "131b37fb",
   "metadata": {},
   "outputs": [],
   "source": [
    "active=user[user[\"dates\"].isin([\"2014/12/11\",\"2014/12/12\",\"2014/12/13\"])]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "10582a1c",
   "metadata": {},
   "outputs": [],
   "source": [
    "daily=user[~user[\"dates\"].isin([\"2014/12/11\",\"2014/12/12\",\"2014/12/13\"])]\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bfc414bc",
   "metadata": {},
   "source": [
    "### 3）活动期间不同时段的用户行为分析"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "e75bb53e",
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyecharts.charts import Bar"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "35ccdd53",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"74c81d27a4b44c858280710809125861\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_74c81d27a4b44c858280710809125861 = echarts.init(\n",
       "                    document.getElementById('74c81d27a4b44c858280710809125861'), 'white', {renderer: 'canvas'});\n",
       "                var option_74c81d27a4b44c858280710809125861 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"bar\",\n",
       "            \"name\": \"\\u6d4f\\u89c8\\u4eba\\u6570\",\n",
       "            \"xAxisIndex\": 0,\n",
       "            \"yAxisIndex\": 0,\n",
       "            \"legendHoverLink\": true,\n",
       "            \"data\": [\n",
       "                24245.0,\n",
       "                11339.0,\n",
       "                6523.0,\n",
       "                4108.0,\n",
       "                3127.0,\n",
       "                3423.0,\n",
       "                6896.0,\n",
       "                17542.0,\n",
       "                23936.0,\n",
       "                26497.0,\n",
       "                30613.0,\n",
       "                27772.0,\n",
       "                28740.0,\n",
       "                30943.0,\n",
       "                29105.0,\n",
       "                30017.0,\n",
       "                28863.0,\n",
       "                25350.0,\n",
       "                28554.0,\n",
       "                39194.0,\n",
       "                48822.0,\n",
       "                60389.0,\n",
       "                60660.0,\n",
       "                49884.0\n",
       "            ],\n",
       "            \"showBackground\": false,\n",
       "            \"barMinHeight\": 0,\n",
       "            \"barCategoryGap\": \"20%\",\n",
       "            \"barGap\": \"30%\",\n",
       "            \"large\": false,\n",
       "            \"largeThreshold\": 400,\n",
       "            \"seriesLayoutBy\": \"column\",\n",
       "            \"datasetIndex\": 0,\n",
       "            \"clip\": true,\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 2,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            }\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"line\",\n",
       "            \"name\": \"\\u52a0\\u8d2d\\u4eba\\u6570\",\n",
       "            \"connectNulls\": false,\n",
       "            \"xAxisIndex\": 1,\n",
       "            \"yAxisIndex\": 1,\n",
       "            \"symbolSize\": 4,\n",
       "            \"showSymbol\": true,\n",
       "            \"smooth\": false,\n",
       "            \"clip\": true,\n",
       "            \"step\": false,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    0,\n",
       "                    2100.0\n",
       "                ],\n",
       "                [\n",
       "                    1,\n",
       "                    744.0\n",
       "                ],\n",
       "                [\n",
       "                    2,\n",
       "                    406.0\n",
       "                ],\n",
       "                [\n",
       "                    3,\n",
       "                    257.0\n",
       "                ],\n",
       "                [\n",
       "                    4,\n",
       "                    235.0\n",
       "                ],\n",
       "                [\n",
       "                    5,\n",
       "                    286.0\n",
       "                ],\n",
       "                [\n",
       "                    6,\n",
       "                    431.0\n",
       "                ],\n",
       "                [\n",
       "                    7,\n",
       "                    700.0\n",
       "                ],\n",
       "                [\n",
       "                    8,\n",
       "                    1058.0\n",
       "                ],\n",
       "                [\n",
       "                    9,\n",
       "                    1249.0\n",
       "                ],\n",
       "                [\n",
       "                    10,\n",
       "                    1509.0\n",
       "                ],\n",
       "                [\n",
       "                    11,\n",
       "                    1416.0\n",
       "                ],\n",
       "                [\n",
       "                    12,\n",
       "                    1323.0\n",
       "                ],\n",
       "                [\n",
       "                    13,\n",
       "                    1481.0\n",
       "                ],\n",
       "                [\n",
       "                    14,\n",
       "                    1394.0\n",
       "                ],\n",
       "                [\n",
       "                    15,\n",
       "                    1380.0\n",
       "                ],\n",
       "                [\n",
       "                    16,\n",
       "                    1310.0\n",
       "                ],\n",
       "                [\n",
       "                    17,\n",
       "                    1223.0\n",
       "                ],\n",
       "                [\n",
       "                    18,\n",
       "                    1283.0\n",
       "                ],\n",
       "                [\n",
       "                    19,\n",
       "                    1675.0\n",
       "                ],\n",
       "                [\n",
       "                    20,\n",
       "                    2131.0\n",
       "                ],\n",
       "                [\n",
       "                    21,\n",
       "                    2675.0\n",
       "                ],\n",
       "                [\n",
       "                    22,\n",
       "                    2878.0\n",
       "                ],\n",
       "                [\n",
       "                    23,\n",
       "                    3007.0\n",
       "                ]\n",
       "            ],\n",
       "            \"hoverAnimation\": true,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"lineStyle\": {\n",
       "                \"show\": true,\n",
       "                \"width\": 1,\n",
       "                \"opacity\": 1,\n",
       "                \"curveness\": 0,\n",
       "                \"type\": \"solid\"\n",
       "            },\n",
       "            \"areaStyle\": {\n",
       "                \"opacity\": 0\n",
       "            },\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 0\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"line\",\n",
       "            \"name\": \"\\u6536\\u85cf\\u4eba\\u6570\",\n",
       "            \"connectNulls\": false,\n",
       "            \"xAxisIndex\": 1,\n",
       "            \"yAxisIndex\": 1,\n",
       "            \"symbolSize\": 4,\n",
       "            \"showSymbol\": true,\n",
       "            \"smooth\": false,\n",
       "            \"clip\": true,\n",
       "            \"step\": false,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    0,\n",
       "                    845.0\n",
       "                ],\n",
       "                [\n",
       "                    1,\n",
       "                    395.0\n",
       "                ],\n",
       "                [\n",
       "                    2,\n",
       "                    290.0\n",
       "                ],\n",
       "                [\n",
       "                    3,\n",
       "                    136.0\n",
       "                ],\n",
       "                [\n",
       "                    4,\n",
       "                    107.0\n",
       "                ],\n",
       "                [\n",
       "                    5,\n",
       "                    101.0\n",
       "                ],\n",
       "                [\n",
       "                    6,\n",
       "                    228.0\n",
       "                ],\n",
       "                [\n",
       "                    7,\n",
       "                    405.0\n",
       "                ],\n",
       "                [\n",
       "                    8,\n",
       "                    653.0\n",
       "                ],\n",
       "                [\n",
       "                    9,\n",
       "                    635.0\n",
       "                ],\n",
       "                [\n",
       "                    10,\n",
       "                    809.0\n",
       "                ],\n",
       "                [\n",
       "                    11,\n",
       "                    691.0\n",
       "                ],\n",
       "                [\n",
       "                    12,\n",
       "                    764.0\n",
       "                ],\n",
       "                [\n",
       "                    13,\n",
       "                    844.0\n",
       "                ],\n",
       "                [\n",
       "                    14,\n",
       "                    798.0\n",
       "                ],\n",
       "                [\n",
       "                    15,\n",
       "                    769.0\n",
       "                ],\n",
       "                [\n",
       "                    16,\n",
       "                    760.0\n",
       "                ],\n",
       "                [\n",
       "                    17,\n",
       "                    745.0\n",
       "                ],\n",
       "                [\n",
       "                    18,\n",
       "                    742.0\n",
       "                ],\n",
       "                [\n",
       "                    19,\n",
       "                    904.0\n",
       "                ],\n",
       "                [\n",
       "                    20,\n",
       "                    1205.0\n",
       "                ],\n",
       "                [\n",
       "                    21,\n",
       "                    1379.0\n",
       "                ],\n",
       "                [\n",
       "                    22,\n",
       "                    1583.0\n",
       "                ],\n",
       "                [\n",
       "                    23,\n",
       "                    1284.0\n",
       "                ]\n",
       "            ],\n",
       "            \"hoverAnimation\": true,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"lineStyle\": {\n",
       "                \"show\": true,\n",
       "                \"width\": 1,\n",
       "                \"opacity\": 1,\n",
       "                \"curveness\": 0,\n",
       "                \"type\": \"solid\"\n",
       "            },\n",
       "            \"areaStyle\": {\n",
       "                \"opacity\": 0\n",
       "            },\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 0\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"line\",\n",
       "            \"name\": \"\\u8d2d\\u4e70\\u4eba\\u6570\",\n",
       "            \"connectNulls\": false,\n",
       "            \"xAxisIndex\": 1,\n",
       "            \"yAxisIndex\": 1,\n",
       "            \"symbolSize\": 4,\n",
       "            \"showSymbol\": true,\n",
       "            \"smooth\": false,\n",
       "            \"clip\": true,\n",
       "            \"step\": false,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    0,\n",
       "                    1492.0\n",
       "                ],\n",
       "                [\n",
       "                    1,\n",
       "                    314.0\n",
       "                ],\n",
       "                [\n",
       "                    2,\n",
       "                    180.0\n",
       "                ],\n",
       "                [\n",
       "                    3,\n",
       "                    94.0\n",
       "                ],\n",
       "                [\n",
       "                    4,\n",
       "                    81.0\n",
       "                ],\n",
       "                [\n",
       "                    5,\n",
       "                    93.0\n",
       "                ],\n",
       "                [\n",
       "                    6,\n",
       "                    196.0\n",
       "                ],\n",
       "                [\n",
       "                    7,\n",
       "                    342.0\n",
       "                ],\n",
       "                [\n",
       "                    8,\n",
       "                    527.0\n",
       "                ],\n",
       "                [\n",
       "                    9,\n",
       "                    674.0\n",
       "                ],\n",
       "                [\n",
       "                    10,\n",
       "                    767.0\n",
       "                ],\n",
       "                [\n",
       "                    11,\n",
       "                    745.0\n",
       "                ],\n",
       "                [\n",
       "                    12,\n",
       "                    653.0\n",
       "                ],\n",
       "                [\n",
       "                    13,\n",
       "                    712.0\n",
       "                ],\n",
       "                [\n",
       "                    14,\n",
       "                    601.0\n",
       "                ],\n",
       "                [\n",
       "                    15,\n",
       "                    618.0\n",
       "                ],\n",
       "                [\n",
       "                    16,\n",
       "                    584.0\n",
       "                ],\n",
       "                [\n",
       "                    17,\n",
       "                    474.0\n",
       "                ],\n",
       "                [\n",
       "                    18,\n",
       "                    519.0\n",
       "                ],\n",
       "                [\n",
       "                    19,\n",
       "                    600.0\n",
       "                ],\n",
       "                [\n",
       "                    20,\n",
       "                    729.0\n",
       "                ],\n",
       "                [\n",
       "                    21,\n",
       "                    867.0\n",
       "                ],\n",
       "                [\n",
       "                    22,\n",
       "                    825.0\n",
       "                ],\n",
       "                [\n",
       "                    23,\n",
       "                    959.0\n",
       "                ]\n",
       "            ],\n",
       "            \"hoverAnimation\": true,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"lineStyle\": {\n",
       "                \"show\": true,\n",
       "                \"width\": 1,\n",
       "                \"opacity\": 1,\n",
       "                \"curveness\": 0,\n",
       "                \"type\": \"solid\"\n",
       "            },\n",
       "            \"areaStyle\": {\n",
       "                \"opacity\": 0\n",
       "            },\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 0\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u6d4f\\u89c8\\u4eba\\u6570\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\\u6d4f\\u89c8\\u4eba\\u6570\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        },\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u52a0\\u8d2d\\u4eba\\u6570\",\n",
       "                \"\\u6536\\u85cf\\u4eba\\u6570\",\n",
       "                \"\\u8d2d\\u4e70\\u4eba\\u6570\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\\u52a0\\u8d2d\\u4eba\\u6570\": true,\n",
       "                \"\\u6536\\u85cf\\u4eba\\u6570\": true,\n",
       "                \"\\u8d2d\\u4e70\\u4eba\\u6570\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"top\": \"48%\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"xAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            },\n",
       "            \"data\": [\n",
       "                0,\n",
       "                1,\n",
       "                2,\n",
       "                3,\n",
       "                4,\n",
       "                5,\n",
       "                6,\n",
       "                7,\n",
       "                8,\n",
       "                9,\n",
       "                10,\n",
       "                11,\n",
       "                12,\n",
       "                13,\n",
       "                14,\n",
       "                15,\n",
       "                16,\n",
       "                17,\n",
       "                18,\n",
       "                19,\n",
       "                20,\n",
       "                21,\n",
       "                22,\n",
       "                23\n",
       "            ]\n",
       "        },\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 1,\n",
       "            \"axisLabel\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"rotate\": 15,\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            },\n",
       "            \"data\": [\n",
       "                0,\n",
       "                1,\n",
       "                2,\n",
       "                3,\n",
       "                4,\n",
       "                5,\n",
       "                6,\n",
       "                7,\n",
       "                8,\n",
       "                9,\n",
       "                10,\n",
       "                11,\n",
       "                12,\n",
       "                13,\n",
       "                14,\n",
       "                15,\n",
       "                16,\n",
       "                17,\n",
       "                18,\n",
       "                19,\n",
       "                20,\n",
       "                21,\n",
       "                22,\n",
       "                23\n",
       "            ]\n",
       "        }\n",
       "    ],\n",
       "    \"yAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        },\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 1,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u6d3b\\u52a8pv\\u5bf9\\u6bd4\\u6570\\u636e\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        },\n",
       "        {\n",
       "            \"text\": \"\\u65e5\\u5747\\u5404\\u65f6\\u6bb5\\u6d3b\\u52a8\\u7528\\u6237\\u884c\\u4e3a\",\n",
       "            \"top\": \"48%\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ],\n",
       "    \"grid\": [\n",
       "        {\n",
       "            \"show\": false,\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 2,\n",
       "            \"bottom\": \"60%\",\n",
       "            \"containLabel\": false,\n",
       "            \"backgroundColor\": \"transparent\",\n",
       "            \"borderColor\": \"#ccc\",\n",
       "            \"borderWidth\": 1\n",
       "        },\n",
       "        {\n",
       "            \"show\": false,\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 2,\n",
       "            \"top\": \"60%\",\n",
       "            \"containLabel\": false,\n",
       "            \"backgroundColor\": \"transparent\",\n",
       "            \"borderColor\": \"#ccc\",\n",
       "            \"borderWidth\": 1\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_74c81d27a4b44c858280710809125861.setOption(option_74c81d27a4b44c858280710809125861);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x211767b1160>"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cart_h= active[active.behavior_type == '3'].groupby('hour')['behavior_type'].count()\n",
    "collect_h=active[active.behavior_type=='2'].groupby('hour')['behavior_type'].count()\n",
    "buy_h=active[active.behavior_type=='4'].groupby('hour')['behavior_type'].count()\n",
    "uv_h=active[active.behavior_type== '1'].groupby('hour')['user_id'].count()\n",
    "\n",
    "attr_h=list(cart_h.index)\n",
    "h1=np.around(cart_h.values/3,decimals=0).tolist()\n",
    "h2=np.around(collect_h.values/3,decimals=0).tolist()\n",
    "h3=np.around(buy_h.values/3,decimals=0).tolist()\n",
    "h4=np.around(uv_h.values/3,decimals=0).tolist()\n",
    "\n",
    "h=(\n",
    "    Line(init_opts=opts.InitOpts(width=\"1000px\",height=\"500px\"))\n",
    "    .add_xaxis(xaxis_data=attr_h)\n",
    "    .add_yaxis(\n",
    "        \"加购人数\",\n",
    "        h1,\n",
    "        label_opts=opts.LabelOpts(is_show=False)\n",
    "    )\n",
    "    .add_yaxis(\n",
    "        \"收藏人数\",\n",
    "        h2,\n",
    "        label_opts=opts.LabelOpts(is_show=False)\n",
    "    )\n",
    "    .add_yaxis(\n",
    "        \"购买人数\",\n",
    "        h3,\n",
    "        label_opts=opts.LabelOpts(is_show=False)\n",
    "    )\n",
    "    .set_global_opts(\n",
    "        xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=15)),\n",
    "        title_opts=opts.TitleOpts(title=\"日均各时段活动用户行为\",pos_top=\"48%\"),\n",
    "        legend_opts=opts.LegendOpts(pos_top=\"48%\"),\n",
    "    )\n",
    ")\n",
    "bar=(\n",
    "    Bar()\n",
    "    .add_xaxis(xaxis_data=attr_h)\n",
    "    .add_yaxis(\n",
    "    \"浏览人数\",\n",
    "        h4,\n",
    "        label_opts=opts.LabelOpts(is_show=False)\n",
    "    )\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title=\"活动pv对比数据\"),\n",
    "    )\n",
    ")\n",
    "\n",
    "ggrid = (\n",
    "    Grid()\n",
    "    .add(bar, grid_opts=opts.GridOpts(pos_bottom=\"60%\"))\n",
    "    .add(h, grid_opts=opts.GridOpts(pos_top=\"60%\"))\n",
    ")\n",
    "ggrid.render_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f45f1d92",
   "metadata": {},
   "source": [
    "——这是三天活动的日均数据，可以发现活动期间是商家在起主导作用大促集中在零点，因此用户的购买高峰也出现在0点，\n",
    "点击浏览的高峰集中在晚上的21点到22点之间，因此商家可以在20点前改好促销页面吸引顾客参加0点的活动"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8d4003b9",
   "metadata": {},
   "source": [
    "### 4）日常期间不同时段的用户行为分析"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "b3e736ec",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"a1963e560fc0413d9b024c2a45d0d36c\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_a1963e560fc0413d9b024c2a45d0d36c = echarts.init(\n",
       "                    document.getElementById('a1963e560fc0413d9b024c2a45d0d36c'), 'white', {renderer: 'canvas'});\n",
       "                var option_a1963e560fc0413d9b024c2a45d0d36c = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"bar\",\n",
       "            \"name\": \"\\u6d4f\\u89c8\\u4eba\\u6570\",\n",
       "            \"xAxisIndex\": 0,\n",
       "            \"yAxisIndex\": 0,\n",
       "            \"legendHoverLink\": true,\n",
       "            \"data\": [\n",
       "                12765.0,\n",
       "                6614.0,\n",
       "                3819.0,\n",
       "                2516.0,\n",
       "                1997.0,\n",
       "                2229.0,\n",
       "                4423.0,\n",
       "                10037.0,\n",
       "                14059.0,\n",
       "                17009.0,\n",
       "                19921.0,\n",
       "                19160.0,\n",
       "                19980.0,\n",
       "                22204.0,\n",
       "                21846.0,\n",
       "                21946.0,\n",
       "                21561.0,\n",
       "                19209.0,\n",
       "                20903.0,\n",
       "                28234.0,\n",
       "                34893.0,\n",
       "                41243.0,\n",
       "                40216.0,\n",
       "                29425.0\n",
       "            ],\n",
       "            \"showBackground\": false,\n",
       "            \"barMinHeight\": 0,\n",
       "            \"barCategoryGap\": \"20%\",\n",
       "            \"barGap\": \"30%\",\n",
       "            \"large\": false,\n",
       "            \"largeThreshold\": 400,\n",
       "            \"seriesLayoutBy\": \"column\",\n",
       "            \"datasetIndex\": 0,\n",
       "            \"clip\": true,\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 2,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            }\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"line\",\n",
       "            \"name\": \"\\u52a0\\u8d2d\\u4eba\\u6570\",\n",
       "            \"connectNulls\": false,\n",
       "            \"xAxisIndex\": 1,\n",
       "            \"yAxisIndex\": 1,\n",
       "            \"symbolSize\": 4,\n",
       "            \"showSymbol\": true,\n",
       "            \"smooth\": false,\n",
       "            \"clip\": true,\n",
       "            \"step\": false,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    0,\n",
       "                    646.0\n",
       "                ],\n",
       "                [\n",
       "                    1,\n",
       "                    338.0\n",
       "                ],\n",
       "                [\n",
       "                    2,\n",
       "                    199.0\n",
       "                ],\n",
       "                [\n",
       "                    3,\n",
       "                    129.0\n",
       "                ],\n",
       "                [\n",
       "                    4,\n",
       "                    110.0\n",
       "                ],\n",
       "                [\n",
       "                    5,\n",
       "                    117.0\n",
       "                ],\n",
       "                [\n",
       "                    6,\n",
       "                    222.0\n",
       "                ],\n",
       "                [\n",
       "                    7,\n",
       "                    387.0\n",
       "                ],\n",
       "                [\n",
       "                    8,\n",
       "                    546.0\n",
       "                ],\n",
       "                [\n",
       "                    9,\n",
       "                    729.0\n",
       "                ],\n",
       "                [\n",
       "                    10,\n",
       "                    918.0\n",
       "                ],\n",
       "                [\n",
       "                    11,\n",
       "                    882.0\n",
       "                ],\n",
       "                [\n",
       "                    12,\n",
       "                    884.0\n",
       "                ],\n",
       "                [\n",
       "                    13,\n",
       "                    1002.0\n",
       "                ],\n",
       "                [\n",
       "                    14,\n",
       "                    985.0\n",
       "                ],\n",
       "                [\n",
       "                    15,\n",
       "                    1032.0\n",
       "                ],\n",
       "                [\n",
       "                    16,\n",
       "                    988.0\n",
       "                ],\n",
       "                [\n",
       "                    17,\n",
       "                    821.0\n",
       "                ],\n",
       "                [\n",
       "                    18,\n",
       "                    869.0\n",
       "                ],\n",
       "                [\n",
       "                    19,\n",
       "                    1166.0\n",
       "                ],\n",
       "                [\n",
       "                    20,\n",
       "                    1454.0\n",
       "                ],\n",
       "                [\n",
       "                    21,\n",
       "                    1790.0\n",
       "                ],\n",
       "                [\n",
       "                    22,\n",
       "                    1766.0\n",
       "                ],\n",
       "                [\n",
       "                    23,\n",
       "                    1436.0\n",
       "                ]\n",
       "            ],\n",
       "            \"hoverAnimation\": true,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"lineStyle\": {\n",
       "                \"show\": true,\n",
       "                \"width\": 1,\n",
       "                \"opacity\": 1,\n",
       "                \"curveness\": 0,\n",
       "                \"type\": \"solid\"\n",
       "            },\n",
       "            \"areaStyle\": {\n",
       "                \"opacity\": 0\n",
       "            },\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 0\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"line\",\n",
       "            \"name\": \"\\u6536\\u85cf\\u4eba\\u6570\",\n",
       "            \"connectNulls\": false,\n",
       "            \"xAxisIndex\": 1,\n",
       "            \"yAxisIndex\": 1,\n",
       "            \"symbolSize\": 4,\n",
       "            \"showSymbol\": true,\n",
       "            \"smooth\": false,\n",
       "            \"clip\": true,\n",
       "            \"step\": false,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    0,\n",
       "                    601.0\n",
       "                ],\n",
       "                [\n",
       "                    1,\n",
       "                    346.0\n",
       "                ],\n",
       "                [\n",
       "                    2,\n",
       "                    196.0\n",
       "                ],\n",
       "                [\n",
       "                    3,\n",
       "                    119.0\n",
       "                ],\n",
       "                [\n",
       "                    4,\n",
       "                    96.0\n",
       "                ],\n",
       "                [\n",
       "                    5,\n",
       "                    113.0\n",
       "                ],\n",
       "                [\n",
       "                    6,\n",
       "                    207.0\n",
       "                ],\n",
       "                [\n",
       "                    7,\n",
       "                    345.0\n",
       "                ],\n",
       "                [\n",
       "                    8,\n",
       "                    471.0\n",
       "                ],\n",
       "                [\n",
       "                    9,\n",
       "                    587.0\n",
       "                ],\n",
       "                [\n",
       "                    10,\n",
       "                    658.0\n",
       "                ],\n",
       "                [\n",
       "                    11,\n",
       "                    648.0\n",
       "                ],\n",
       "                [\n",
       "                    12,\n",
       "                    643.0\n",
       "                ],\n",
       "                [\n",
       "                    13,\n",
       "                    718.0\n",
       "                ],\n",
       "                [\n",
       "                    14,\n",
       "                    703.0\n",
       "                ],\n",
       "                [\n",
       "                    15,\n",
       "                    697.0\n",
       "                ],\n",
       "                [\n",
       "                    16,\n",
       "                    689.0\n",
       "                ],\n",
       "                [\n",
       "                    17,\n",
       "                    620.0\n",
       "                ],\n",
       "                [\n",
       "                    18,\n",
       "                    616.0\n",
       "                ],\n",
       "                [\n",
       "                    19,\n",
       "                    848.0\n",
       "                ],\n",
       "                [\n",
       "                    20,\n",
       "                    1047.0\n",
       "                ],\n",
       "                [\n",
       "                    21,\n",
       "                    1193.0\n",
       "                ],\n",
       "                [\n",
       "                    22,\n",
       "                    1259.0\n",
       "                ],\n",
       "                [\n",
       "                    23,\n",
       "                    1018.0\n",
       "                ]\n",
       "            ],\n",
       "            \"hoverAnimation\": true,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"lineStyle\": {\n",
       "                \"show\": true,\n",
       "                \"width\": 1,\n",
       "                \"opacity\": 1,\n",
       "                \"curveness\": 0,\n",
       "                \"type\": \"solid\"\n",
       "            },\n",
       "            \"areaStyle\": {\n",
       "                \"opacity\": 0\n",
       "            },\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 0\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"line\",\n",
       "            \"name\": \"\\u8d2d\\u4e70\\u4eba\\u6570\",\n",
       "            \"connectNulls\": false,\n",
       "            \"xAxisIndex\": 1,\n",
       "            \"yAxisIndex\": 1,\n",
       "            \"symbolSize\": 4,\n",
       "            \"showSymbol\": true,\n",
       "            \"smooth\": false,\n",
       "            \"clip\": true,\n",
       "            \"step\": false,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    0,\n",
       "                    152.0\n",
       "                ],\n",
       "                [\n",
       "                    1,\n",
       "                    72.0\n",
       "                ],\n",
       "                [\n",
       "                    2,\n",
       "                    34.0\n",
       "                ],\n",
       "                [\n",
       "                    3,\n",
       "                    23.0\n",
       "                ],\n",
       "                [\n",
       "                    4,\n",
       "                    17.0\n",
       "                ],\n",
       "                [\n",
       "                    5,\n",
       "                    17.0\n",
       "                ],\n",
       "                [\n",
       "                    6,\n",
       "                    43.0\n",
       "                ],\n",
       "                [\n",
       "                    7,\n",
       "                    77.0\n",
       "                ],\n",
       "                [\n",
       "                    8,\n",
       "                    163.0\n",
       "                ],\n",
       "                [\n",
       "                    9,\n",
       "                    267.0\n",
       "                ],\n",
       "                [\n",
       "                    10,\n",
       "                    387.0\n",
       "                ],\n",
       "                [\n",
       "                    11,\n",
       "                    362.0\n",
       "                ],\n",
       "                [\n",
       "                    12,\n",
       "                    368.0\n",
       "                ],\n",
       "                [\n",
       "                    13,\n",
       "                    405.0\n",
       "                ],\n",
       "                [\n",
       "                    14,\n",
       "                    400.0\n",
       "                ],\n",
       "                [\n",
       "                    15,\n",
       "                    411.0\n",
       "                ],\n",
       "                [\n",
       "                    16,\n",
       "                    380.0\n",
       "                ],\n",
       "                [\n",
       "                    17,\n",
       "                    307.0\n",
       "                ],\n",
       "                [\n",
       "                    18,\n",
       "                    277.0\n",
       "                ],\n",
       "                [\n",
       "                    19,\n",
       "                    360.0\n",
       "                ],\n",
       "                [\n",
       "                    20,\n",
       "                    416.0\n",
       "                ],\n",
       "                [\n",
       "                    21,\n",
       "                    496.0\n",
       "                ],\n",
       "                [\n",
       "                    22,\n",
       "                    446.0\n",
       "                ],\n",
       "                [\n",
       "                    23,\n",
       "                    306.0\n",
       "                ]\n",
       "            ],\n",
       "            \"hoverAnimation\": true,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"lineStyle\": {\n",
       "                \"show\": true,\n",
       "                \"width\": 1,\n",
       "                \"opacity\": 1,\n",
       "                \"curveness\": 0,\n",
       "                \"type\": \"solid\"\n",
       "            },\n",
       "            \"areaStyle\": {\n",
       "                \"opacity\": 0\n",
       "            },\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 0\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u6d4f\\u89c8\\u4eba\\u6570\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\\u6d4f\\u89c8\\u4eba\\u6570\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        },\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u52a0\\u8d2d\\u4eba\\u6570\",\n",
       "                \"\\u6536\\u85cf\\u4eba\\u6570\",\n",
       "                \"\\u8d2d\\u4e70\\u4eba\\u6570\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\\u52a0\\u8d2d\\u4eba\\u6570\": true,\n",
       "                \"\\u6536\\u85cf\\u4eba\\u6570\": true,\n",
       "                \"\\u8d2d\\u4e70\\u4eba\\u6570\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"top\": \"48%\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"xAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            },\n",
       "            \"data\": [\n",
       "                0,\n",
       "                1,\n",
       "                2,\n",
       "                3,\n",
       "                4,\n",
       "                5,\n",
       "                6,\n",
       "                7,\n",
       "                8,\n",
       "                9,\n",
       "                10,\n",
       "                11,\n",
       "                12,\n",
       "                13,\n",
       "                14,\n",
       "                15,\n",
       "                16,\n",
       "                17,\n",
       "                18,\n",
       "                19,\n",
       "                20,\n",
       "                21,\n",
       "                22,\n",
       "                23\n",
       "            ]\n",
       "        },\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 1,\n",
       "            \"axisLabel\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"rotate\": 15,\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            },\n",
       "            \"data\": [\n",
       "                0,\n",
       "                1,\n",
       "                2,\n",
       "                3,\n",
       "                4,\n",
       "                5,\n",
       "                6,\n",
       "                7,\n",
       "                8,\n",
       "                9,\n",
       "                10,\n",
       "                11,\n",
       "                12,\n",
       "                13,\n",
       "                14,\n",
       "                15,\n",
       "                16,\n",
       "                17,\n",
       "                18,\n",
       "                19,\n",
       "                20,\n",
       "                21,\n",
       "                22,\n",
       "                23\n",
       "            ]\n",
       "        }\n",
       "    ],\n",
       "    \"yAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        },\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 1,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u65e5\\u5e38pv\\u5bf9\\u6bd4\\u6570\\u636e\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        },\n",
       "        {\n",
       "            \"text\": \"\\u65e5\\u5747\\u5404\\u65f6\\u6bb5\\u6d3b\\u52a8\\u7528\\u6237\\u884c\\u4e3a\",\n",
       "            \"top\": \"48%\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ],\n",
       "    \"grid\": [\n",
       "        {\n",
       "            \"show\": false,\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 2,\n",
       "            \"bottom\": \"60%\",\n",
       "            \"containLabel\": false,\n",
       "            \"backgroundColor\": \"transparent\",\n",
       "            \"borderColor\": \"#ccc\",\n",
       "            \"borderWidth\": 1\n",
       "        },\n",
       "        {\n",
       "            \"show\": false,\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 2,\n",
       "            \"top\": \"60%\",\n",
       "            \"containLabel\": false,\n",
       "            \"backgroundColor\": \"transparent\",\n",
       "            \"borderColor\": \"#ccc\",\n",
       "            \"borderWidth\": 1\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_a1963e560fc0413d9b024c2a45d0d36c.setOption(option_a1963e560fc0413d9b024c2a45d0d36c);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x211767b12e0>"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 日常数据\n",
    "cart_d= daily[daily.behavior_type == '3'].groupby('hour')['behavior_type'].count()\n",
    "collect_d=daily[daily.behavior_type=='2'].groupby('hour')['behavior_type'].count()\n",
    "buy_d=daily[daily.behavior_type=='4'].groupby('hour')['behavior_type'].count()\n",
    "uv_d=daily[daily.behavior_type== '1'].groupby('hour')['user_id'].count()\n",
    "\n",
    "attr_d=list(cart_d.index)\n",
    "d1=np.around(cart_d.values/28,decimals=0).tolist()\n",
    "d2=np.around(collect_d.values/28,decimals=0).tolist()\n",
    "d3=np.around(buy_d.values/28,decimals=0).tolist()\n",
    "d4=np.around(uv_d.values/28,decimals=0).tolist()\n",
    "\n",
    "d=(\n",
    "    Line(init_opts=opts.InitOpts(width=\"1000px\",height=\"500px\"))\n",
    "    .add_xaxis(xaxis_data=attr_d)\n",
    "    .add_yaxis(\n",
    "        \"加购人数\",\n",
    "        d1,\n",
    "        label_opts=opts.LabelOpts(is_show=False)\n",
    "    )\n",
    "    .add_yaxis(\n",
    "        \"收藏人数\",\n",
    "        d2,\n",
    "        label_opts=opts.LabelOpts(is_show=False)\n",
    "    )\n",
    "    .add_yaxis(\n",
    "        \"购买人数\",\n",
    "        d3,\n",
    "        label_opts=opts.LabelOpts(is_show=False)\n",
    "    )\n",
    "    .set_global_opts(\n",
    "        xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=15)),\n",
    "        title_opts=opts.TitleOpts(title=\"日均各时段活动用户行为\",pos_top=\"48%\"),\n",
    "        legend_opts=opts.LegendOpts(pos_top=\"48%\"),\n",
    "    )\n",
    ")\n",
    "y=(\n",
    "    Bar()\n",
    "    .add_xaxis(xaxis_data=attr_d)\n",
    "    .add_yaxis(\n",
    "    \"浏览人数\",\n",
    "        d4,\n",
    "        label_opts=opts.LabelOpts(is_show=False)\n",
    "    )\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title=\"日常pv对比数据\"),\n",
    "    )\n",
    ")\n",
    "\n",
    "ggrid = (\n",
    "    Grid()\n",
    "    .add(y, grid_opts=opts.GridOpts(pos_bottom=\"60%\"))\n",
    "    .add(d, grid_opts=opts.GridOpts(pos_top=\"60%\"))\n",
    ")\n",
    "ggrid.render_notebook()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "22f5b1b3",
   "metadata": {},
   "source": [
    "——与大促不同的是日常期间购买人数从上午10点到晚上23点变化都不会太大高峰出现在晚上21点，pv、加购、收藏的高峰出现在晚上21点到22点之间，说明大家都喜欢在晚上这个时间段浏览商品，日常时可以集中在这个时段进行促销活动，浏览高峰也是集中在晚上21点到22点之间。\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "06592e10",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"c21be429d30445a8af956cdd703ecca8\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_c21be429d30445a8af956cdd703ecca8 = echarts.init(\n",
       "                    document.getElementById('c21be429d30445a8af956cdd703ecca8'), 'white', {renderer: 'canvas'});\n",
       "                var option_c21be429d30445a8af956cdd703ecca8 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"line\",\n",
       "            \"name\": \"\\u65e5\\u5e38\\u8d2d\\u4e70\\u7387\",\n",
       "            \"connectNulls\": false,\n",
       "            \"symbolSize\": 4,\n",
       "            \"showSymbol\": true,\n",
       "            \"smooth\": false,\n",
       "            \"clip\": true,\n",
       "            \"step\": false,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    0,\n",
       "                    0.08\n",
       "                ],\n",
       "                [\n",
       "                    1,\n",
       "                    0.07\n",
       "                ],\n",
       "                [\n",
       "                    2,\n",
       "                    0.06\n",
       "                ],\n",
       "                [\n",
       "                    3,\n",
       "                    0.05\n",
       "                ],\n",
       "                [\n",
       "                    4,\n",
       "                    0.05\n",
       "                ],\n",
       "                [\n",
       "                    5,\n",
       "                    0.04\n",
       "                ],\n",
       "                [\n",
       "                    6,\n",
       "                    0.05\n",
       "                ],\n",
       "                [\n",
       "                    7,\n",
       "                    0.05\n",
       "                ],\n",
       "                [\n",
       "                    8,\n",
       "                    0.07\n",
       "                ],\n",
       "                [\n",
       "                    9,\n",
       "                    0.09\n",
       "                ],\n",
       "                [\n",
       "                    10,\n",
       "                    0.11\n",
       "                ],\n",
       "                [\n",
       "                    11,\n",
       "                    0.1\n",
       "                ],\n",
       "                [\n",
       "                    12,\n",
       "                    0.1\n",
       "                ],\n",
       "                [\n",
       "                    13,\n",
       "                    0.1\n",
       "                ],\n",
       "                [\n",
       "                    14,\n",
       "                    0.11\n",
       "                ],\n",
       "                [\n",
       "                    15,\n",
       "                    0.11\n",
       "                ],\n",
       "                [\n",
       "                    16,\n",
       "                    0.1\n",
       "                ],\n",
       "                [\n",
       "                    17,\n",
       "                    0.09\n",
       "                ],\n",
       "                [\n",
       "                    18,\n",
       "                    0.08\n",
       "                ],\n",
       "                [\n",
       "                    19,\n",
       "                    0.09\n",
       "                ],\n",
       "                [\n",
       "                    20,\n",
       "                    0.09\n",
       "                ],\n",
       "                [\n",
       "                    21,\n",
       "                    0.1\n",
       "                ],\n",
       "                [\n",
       "                    22,\n",
       "                    0.09\n",
       "                ],\n",
       "                [\n",
       "                    23,\n",
       "                    0.09\n",
       "                ]\n",
       "            ],\n",
       "            \"hoverAnimation\": true,\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"lineStyle\": {\n",
       "                \"show\": true,\n",
       "                \"width\": 1,\n",
       "                \"opacity\": 1,\n",
       "                \"curveness\": 0,\n",
       "                \"type\": \"solid\"\n",
       "            },\n",
       "            \"areaStyle\": {\n",
       "                \"opacity\": 0\n",
       "            },\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 0\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"line\",\n",
       "            \"name\": \"\\u6d3b\\u52a8\\u8d2d\\u4e70\\u7387\",\n",
       "            \"connectNulls\": false,\n",
       "            \"symbolSize\": 4,\n",
       "            \"showSymbol\": true,\n",
       "            \"smooth\": false,\n",
       "            \"clip\": true,\n",
       "            \"step\": false,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    0,\n",
       "                    0.26\n",
       "                ],\n",
       "                [\n",
       "                    1,\n",
       "                    0.17\n",
       "                ],\n",
       "                [\n",
       "                    2,\n",
       "                    0.15\n",
       "                ],\n",
       "                [\n",
       "                    3,\n",
       "                    0.13\n",
       "                ],\n",
       "                [\n",
       "                    4,\n",
       "                    0.14\n",
       "                ],\n",
       "                [\n",
       "                    5,\n",
       "                    0.11\n",
       "                ],\n",
       "                [\n",
       "                    6,\n",
       "                    0.12\n",
       "                ],\n",
       "                [\n",
       "                    7,\n",
       "                    0.11\n",
       "                ],\n",
       "                [\n",
       "                    8,\n",
       "                    0.13\n",
       "                ],\n",
       "                [\n",
       "                    9,\n",
       "                    0.14\n",
       "                ],\n",
       "                [\n",
       "                    10,\n",
       "                    0.15\n",
       "                ],\n",
       "                [\n",
       "                    11,\n",
       "                    0.15\n",
       "                ],\n",
       "                [\n",
       "                    12,\n",
       "                    0.14\n",
       "                ],\n",
       "                [\n",
       "                    13,\n",
       "                    0.14\n",
       "                ],\n",
       "                [\n",
       "                    14,\n",
       "                    0.13\n",
       "                ],\n",
       "                [\n",
       "                    15,\n",
       "                    0.13\n",
       "                ],\n",
       "                [\n",
       "                    16,\n",
       "                    0.13\n",
       "                ],\n",
       "                [\n",
       "                    17,\n",
       "                    0.11\n",
       "                ],\n",
       "                [\n",
       "                    18,\n",
       "                    0.11\n",
       "                ],\n",
       "                [\n",
       "                    19,\n",
       "                    0.11\n",
       "                ],\n",
       "                [\n",
       "                    20,\n",
       "                    0.12\n",
       "                ],\n",
       "                [\n",
       "                    21,\n",
       "                    0.12\n",
       "                ],\n",
       "                [\n",
       "                    22,\n",
       "                    0.13\n",
       "                ],\n",
       "                [\n",
       "                    23,\n",
       "                    0.14\n",
       "                ]\n",
       "            ],\n",
       "            \"hoverAnimation\": true,\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"lineStyle\": {\n",
       "                \"show\": true,\n",
       "                \"width\": 1,\n",
       "                \"opacity\": 1,\n",
       "                \"curveness\": 0,\n",
       "                \"type\": \"solid\"\n",
       "            },\n",
       "            \"areaStyle\": {\n",
       "                \"opacity\": 0\n",
       "            },\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 0\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u65e5\\u5e38\\u8d2d\\u4e70\\u7387\",\n",
       "                \"\\u6d3b\\u52a8\\u8d2d\\u4e70\\u7387\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\\u65e5\\u5e38\\u8d2d\\u4e70\\u7387\": true,\n",
       "                \"\\u6d3b\\u52a8\\u8d2d\\u4e70\\u7387\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"xAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            },\n",
       "            \"data\": [\n",
       "                0,\n",
       "                1,\n",
       "                2,\n",
       "                3,\n",
       "                4,\n",
       "                5,\n",
       "                6,\n",
       "                7,\n",
       "                8,\n",
       "                9,\n",
       "                10,\n",
       "                11,\n",
       "                12,\n",
       "                13,\n",
       "                14,\n",
       "                15,\n",
       "                16,\n",
       "                17,\n",
       "                18,\n",
       "                19,\n",
       "                20,\n",
       "                21,\n",
       "                22,\n",
       "                23\n",
       "            ]\n",
       "        }\n",
       "    ],\n",
       "    \"yAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u4e0d\\u540c\\u65f6\\u6bb5\\u8d2d\\u4e70\\u7387\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_c21be429d30445a8af956cdd703ecca8.setOption(option_c21be429d30445a8af956cdd703ecca8);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x211767a0dc0>"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 活动时购买率\n",
    "hour_buy_user_num = active[active.behavior_type == '4'].drop_duplicates(['user_id','dates', 'hour']).groupby('hour')['user_id'].count()\n",
    "hour_active_user_num = active.drop_duplicates(['user_id','dates', 'hour']).groupby('hour')['user_id'].count()\n",
    "hour_buy_rate = hour_buy_user_num / hour_active_user_num\n",
    "attr_o = list(hour_buy_user_num.index)\n",
    "vo_2 =np.around(hour_buy_rate.values,decimals=2) \n",
    "# 日常时购买率\n",
    "hour_buy_daily_num = daily[daily.behavior_type == '4'].drop_duplicates(['user_id','dates', 'hour']).groupby('hour')['user_id'].count()\n",
    "hour_active_daily_num = daily.drop_duplicates(['user_id','dates', 'hour']).groupby('hour')['user_id'].count()\n",
    "daily_buy_rate = hour_buy_daily_num / hour_active_daily_num\n",
    "vi_2 =np.around(daily_buy_rate.values,decimals=2) \n",
    "\n",
    "\n",
    "hbu=(\n",
    "    Line()\n",
    "    .add_xaxis(xaxis_data=attr_o)\n",
    "    .add_yaxis(\n",
    "        \"日常购买率\",\n",
    "        vi_2,\n",
    "    )\n",
    "    .add_yaxis(\n",
    "        \"活动购买率\",\n",
    "        vo_2,\n",
    "    )\n",
    "    .set_global_opts(title_opts=opts.TitleOpts(title=\"不同时段购买率\"))\n",
    ")\n",
    "\n",
    "hbu.render_notebook()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c39cea9e",
   "metadata": {},
   "source": [
    "——日常时的购买率最高的出现在上午10点到下午15点间，还有晚上的21点，和活动期间的购买率不同，但是明显晚上21点已经在分析中出现比较多的峰值，因此可以考虑这个时段做做吸引用户购买的措施。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "eb3e4ba8",
   "metadata": {},
   "source": [
    "### 5）转化漏斗分析"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a9da4632",
   "metadata": {},
   "source": [
    "#### 1）活动期间的转化漏斗¶\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "7e8bfa6c",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"b675cba41fda4d12bc355429b4cf8bef\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_b675cba41fda4d12bc355429b4cf8bef = echarts.init(\n",
       "                    document.getElementById('b675cba41fda4d12bc355429b4cf8bef'), 'white', {renderer: 'canvas'});\n",
       "                var option_b675cba41fda4d12bc355429b4cf8bef = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"funnel\",\n",
       "            \"name\": \"\\u7528\\u6237\\u884c\\u4e3a\",\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u70b9\\u51fb\",\n",
       "                    \"value\": 100.0\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u52a0\\u5165\\u8d2d\\u7269\\u8f66\",\n",
       "                    \"value\": 4.97\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6536\\u85cf\",\n",
       "                    \"value\": 2.64\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u8d2d\\u4e70\",\n",
       "                    \"value\": 2.11\n",
       "                }\n",
       "            ],\n",
       "            \"sort\": \"descending\",\n",
       "            \"gap\": 2,\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"ourside\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"tooltip\": {\n",
       "                \"show\": true,\n",
       "                \"trigger\": \"item\",\n",
       "                \"triggerOn\": \"mousemove|click\",\n",
       "                \"axisPointer\": {\n",
       "                    \"type\": \"line\"\n",
       "                },\n",
       "                \"showContent\": true,\n",
       "                \"alwaysShowContent\": false,\n",
       "                \"showDelay\": 0,\n",
       "                \"hideDelay\": 100,\n",
       "                \"formatter\": \"{a} <br/>{b} : {c}%\",\n",
       "                \"textStyle\": {\n",
       "                    \"fontSize\": 14\n",
       "                },\n",
       "                \"borderWidth\": 0,\n",
       "                \"padding\": 5\n",
       "            },\n",
       "            \"itemStyle\": {\n",
       "                \"borderColor\": \"#fff\",\n",
       "                \"borderWidth\": 1\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u52a0\\u5165\\u8d2d\\u7269\\u8f66\",\n",
       "                \"\\u6536\\u85cf\",\n",
       "                \"\\u8d2d\\u4e70\",\n",
       "                \"\\u70b9\\u51fb\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\\u70b9\\u51fb\": true,\n",
       "                \"\\u52a0\\u5165\\u8d2d\\u7269\\u8f66\": true,\n",
       "                \"\\u6536\\u85cf\": true,\n",
       "                \"\\u8d2d\\u4e70\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u7528\\u6237\\u8f6c\\u5316\\u6f0f\\u6597\",\n",
       "            \"subtext\": \"\\u6d3b\\u52a8\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_b675cba41fda4d12bc355429b4cf8bef.setOption(option_b675cba41fda4d12bc355429b4cf8bef);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x211c88c9160>"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from pyecharts.charts import Funnel\n",
    "\n",
    "# 活动转化\n",
    "a_pv=active[active.behavior_type==\"1\"][\"user_id\"].count()\n",
    "a_cart=active[active.behavior_type==\"3\"][\"user_id\"].count()\n",
    "a_collect=active[active.behavior_type==\"2\"][\"user_id\"].count()\n",
    "a_buy=active[active.behavior_type==\"4\"][\"user_id\"].count()\n",
    "\n",
    "a_attr=[\"点击\",\"加入购物车\",\"收藏\",\"购买\"]\n",
    "values=[np.around((a_pv/a_pv*100),2),\n",
    "        np.around((a_cart/a_pv*100),2),\n",
    "        np.around((a_collect/a_pv*100),2),\n",
    "        np.around((a_buy/a_pv*100),2),\n",
    "       ]\n",
    "\n",
    "data = [[a_attr[i], values[i]] for i in range(len(a_attr))]\n",
    "\n",
    "a=(\n",
    "    Funnel()\n",
    "    .add(\n",
    "        series_name=\"用户行为\",\n",
    "        data_pair=data,\n",
    "        gap=2,\n",
    "        tooltip_opts=opts.TooltipOpts(trigger=\"item\", formatter=\"{a} <br/>{b} : {c}%\",is_show=True),\n",
    "        label_opts=opts.LabelOpts(is_show=True, position=\"ourside\"),\n",
    "        itemstyle_opts=opts.ItemStyleOpts(border_color=\"#fff\", border_width=1),\n",
    "    )\n",
    "    .set_global_opts(title_opts=opts.TitleOpts(title=\"用户转化漏斗\", subtitle=\"活动\"))\n",
    ")\n",
    "\n",
    "a.render_notebook()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "22c33916",
   "metadata": {},
   "source": [
    "——活动期间日均从点击到加入购物车的转化率只有4.97%，购买的只有2%，说明点击浏览量不少但是吸引不了顾客购买，虽然是大的活动，但是转化率还是很低的，\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f6bae49b",
   "metadata": {},
   "source": [
    "#### 2）日常期间的转化漏斗"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "7bae0250",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"f3c56cc1e3714aada44d6d637c3c5c26\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_f3c56cc1e3714aada44d6d637c3c5c26 = echarts.init(\n",
       "                    document.getElementById('f3c56cc1e3714aada44d6d637c3c5c26'), 'white', {renderer: 'canvas'});\n",
       "                var option_f3c56cc1e3714aada44d6d637c3c5c26 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"funnel\",\n",
       "            \"name\": \"\\u7528\\u6237\\u884c\\u4e3a\",\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u70b9\\u51fb\",\n",
       "                    \"value\": 100.0\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u52a0\\u5165\\u8d2d\\u7269\\u8f66\",\n",
       "                    \"value\": 4.45\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6536\\u85cf\",\n",
       "                    \"value\": 3.31\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u8d2d\\u4e70\",\n",
       "                    \"value\": 1.42\n",
       "                }\n",
       "            ],\n",
       "            \"sort\": \"descending\",\n",
       "            \"gap\": 2,\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"ourside\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"tooltip\": {\n",
       "                \"show\": true,\n",
       "                \"trigger\": \"item\",\n",
       "                \"triggerOn\": \"mousemove|click\",\n",
       "                \"axisPointer\": {\n",
       "                    \"type\": \"line\"\n",
       "                },\n",
       "                \"showContent\": true,\n",
       "                \"alwaysShowContent\": false,\n",
       "                \"showDelay\": 0,\n",
       "                \"hideDelay\": 100,\n",
       "                \"formatter\": \"{a} <br/>{b} : {c}%\",\n",
       "                \"textStyle\": {\n",
       "                    \"fontSize\": 14\n",
       "                },\n",
       "                \"borderWidth\": 0,\n",
       "                \"padding\": 5\n",
       "            },\n",
       "            \"itemStyle\": {\n",
       "                \"borderColor\": \"#fff\",\n",
       "                \"borderWidth\": 1\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u52a0\\u5165\\u8d2d\\u7269\\u8f66\",\n",
       "                \"\\u6536\\u85cf\",\n",
       "                \"\\u8d2d\\u4e70\",\n",
       "                \"\\u70b9\\u51fb\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\\u70b9\\u51fb\": true,\n",
       "                \"\\u52a0\\u5165\\u8d2d\\u7269\\u8f66\": true,\n",
       "                \"\\u6536\\u85cf\": true,\n",
       "                \"\\u8d2d\\u4e70\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u7528\\u6237\\u8f6c\\u5316\\u6f0f\\u6597\",\n",
       "            \"subtext\": \"\\u65e5\\u5e38\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_f3c56cc1e3714aada44d6d637c3c5c26.setOption(option_f3c56cc1e3714aada44d6d637c3c5c26);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x212047cc640>"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    " #日常转化\n",
    "l_pv=daily[daily.behavior_type==\"1\"][\"user_id\"].count()\n",
    "l_cart=daily[daily.behavior_type==\"3\"][\"user_id\"].count()\n",
    "l_collect=daily[daily.behavior_type==\"2\"][\"user_id\"].count()\n",
    "l_buy=daily[daily.behavior_type==\"4\"][\"user_id\"].count()\n",
    "\n",
    "l_attr=[\"点击\",\"加入购物车\",\"收藏\",\"购买\"]\n",
    "valuel=[np.around((l_pv/l_pv*100),2),\n",
    "        np.around((l_cart/l_pv*100),2),\n",
    "        np.around((l_collect/l_pv*100),2),\n",
    "        np.around((l_buy/l_pv*100),2),\n",
    "       ]\n",
    "\n",
    "datal = [[l_attr[i], valuel[i]] for i in range(len(l_attr))]\n",
    "\n",
    "dy=(\n",
    "    Funnel()\n",
    "    .add(\n",
    "        series_name=\"用户行为\",\n",
    "        data_pair=datal,\n",
    "        gap=2,\n",
    "        tooltip_opts=opts.TooltipOpts(trigger=\"item\", formatter=\"{a} <br/>{b} : {c}%\",is_show=True),\n",
    "        label_opts=opts.LabelOpts(is_show=True, position=\"ourside\"),\n",
    "        itemstyle_opts=opts.ItemStyleOpts(border_color=\"#fff\", border_width=1),\n",
    "    )\n",
    "    .set_global_opts(title_opts=opts.TitleOpts(title=\"用户转化漏斗\", subtitle=\"日常\"))\n",
    ")\n",
    "dy.render_notebook()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "93b25a6c",
   "metadata": {},
   "source": [
    "——日常期间总的点击量中，有4.45%加入购物车，有3.3%收藏，而到最后只有1.4%购买，整体来看，购买的转化率最低，有很大的增长空间；\n",
    "——就颜色来看，红色部分的变化最大，即“点击-加入购物车“这一环节的转化率最低，按照“点击-加入购物车-收藏-购买”这一用户行为路径，我们可通过优化“点击-加入购物车”这一环节进而提升购买的转化率，可以通过鼓励用户收藏加购后可以领券来刺激用户加购收藏从而刺激用户的购买欲望。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e15c649c",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
